import java.util.ArrayList;
import java.util.List;

/**
 * 77. 组合
 * https://leetcode.cn/problems/combinations/description/
 */
class Solution {
    List<Integer> path;
    List<List<Integer>> ret;
    int n, k;
    public List<List<Integer>> combine(int _n, int _k) {
        path = new ArrayList<>();
        ret = new ArrayList<>();
        n = _n;
        k = _k;
        dfs(1);
        return ret;
    }
    void dfs(int start) {
        if(path.size() == k) {
            ret.add(new ArrayList<>(path));
            return;
        }
        for(int i = start; i <= n; i++) {
            path.add(i);
            dfs(i + 1);
            path.remove(path.size() - 1);//恢复现场
        }
    }
}